using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_TraLoiUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            LoadData();
            LoadDropDownList();
        }
    }
    private void LoadDropDownList()
    {
        tbBinhLuanCollection blCollection=tbBinhLuanBUS .GetAll ();
        ddl_binhluan .DataTextField =tbBinhLuanColumns .NoiDung .ToString ();
        ddl_binhluan .DataValueField =tbBinhLuanColumns .MaBL .ToString ();
        ddl_binhluan .DataSource =blCollection ;
        ddl_binhluan .DataBind ();
        ddl_binhluan .Items .Insert (0,new ListItem ("All","0"));

        tbKhachHangCollection khCollection=tbKhachHangBUS .GetAll ();
        ddl_khachhang .DataTextField =tbKhachHangColumns .HoTen .ToString ();
        ddl_khachhang .DataValueField =tbKhachHangColumns .MaKH .ToString ();
        ddl_khachhang .DataSource =khCollection ;
        ddl_khachhang .DataBind ();
        ddl_khachhang .Items .Insert (0,new ListItem ("All","0"));
    }
    private void LoadData()
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            txt_matraloi.Text = iD.ToString();
            tbTraLoi traloi = tbTraLoiBUS.GetByID(iD);
            ddl_binhluan.SelectedValue=traloi .BinhLuan.ToString () ;
            ddl_khachhang.SelectedValue=traloi .KhachHang.ToString () ;
            txt_traloi.Text=traloi .TraLoi ;
            txt_ngaytraloi.Text=traloi .NgayTraLoi ;

        }
        catch
        {
            Response.Redirect("~/Admin/TraLoiDanhSach.aspx");   
        }
        
    }

    protected void btn_sua_Click(object sender, EventArgs e)
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            tbTraLoi traloi = tbTraLoiBUS.GetByID(iD);
            traloi.BinhLuan = int.Parse(ddl_binhluan.SelectedValue);
            traloi.KhachHang = int.Parse(ddl_khachhang.SelectedValue);
            traloi.TraLoi = txt_traloi.Text;
            traloi.NgayTraLoi = txt_ngaytraloi.Text;
            tbTraLoiBUS.Update(traloi);
        }
        catch
        {
        }
        Response.Redirect("~/Admin/TraLoiDanhSach.aspx");
        Response.Redirect(Request.RawUrl);
    }
}
